using System;

namespace OracleInternal.Secure.Network
{
	public class DES112 : DES168
	{
		public override void init(byte[] key, byte[] iv)
		{
			if (key != null || iv != null)
			{
				if (key.Length < 16)
				{
					throw new Exception("Key is too small");
				}
				Array.Copy(key, 0, field_f, 0, 8);
				Array.Copy(key, 8, field_g, 0, 8);
				Array.Copy(field_f, 0, field_h, 0, 8);
				field_p = true;
				return;
			}
			throw new Exception("Key is too small");
		}

		public override void setSessionKey(byte[] key, byte[] iv)
		{
			field_p = true;
			if (key != null || iv != null)
			{
				if (key.Length < 16)
				{
					throw new Exception("Key is too small");
				}
				Array.Copy(key, 0, field_f, 0, 8);
				Array.Copy(key, 8, field_g, 0, 8);
				Array.Copy(field_f, 0, field_h, 0, 8);
			}
			else if (field_f == null)
			{
				throw new Exception("Key is too small");
			}
		}
	}
}
